import random
import string
from datetime import datetime, timedelta

from core.config.mysql_config import MySQLConfig
from service.database_service.mysql.operation.user_crud import UsersCRUD


# 生成随机用户名
def generate_username(length=8):
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for _ in range(length))

# 生成随机生日（范围：1950-01-01 到 2005-12-31）
def generate_birthday():
    start_date = datetime(1950, 1, 1)
    end_date = datetime(2005, 12, 31)
    delta = end_date - start_date
    random_days = random.randint(0, delta.days)
    return (start_date + timedelta(days=random_days)).strftime('%Y-%m-%d')

# 生成 1000 个用户信息
def generate_users(num_users=1000):
    users = []
    for user_id in range(1, num_users + 1):
        user_name = generate_username()
        user_birthday = generate_birthday()
        users.append({
            'user_id': user_id,
            'user_name': user_name,
            'user_birthday': user_birthday
        })
    return users

if __name__ == '__main__':
    # 生成并打印用户信息
    users = generate_users()
    for user in users:
        print(user)

    db = MySQLConfig().get_redis_client()
    UsersCRUD.batch_insert_users(db, users)
